package com.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.util.GetConfig;
import com.util.GsonUtil;
import com.util.WebChatUtil;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/member")
public class MemberController extends BaseAction {

	/**
	 * 我的-会员中心
	 * GetMemAboutDataInfo
	 * @param request
	 * @return
	 */
	@RequestMapping("/memberCenter")
    public ModelAndView memberCenter(HttpServletRequest request){
		ModelAndView md = new ModelAndView("memberCenter");
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/MEM/GetMemAboutDataInfo",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
    		md=new ModelAndView("redirect:/home/gotoRegister");
    		md.addObject("namespase","member");
    		md.addObject("url","memberCenter");
    		return md;
		}else if(memberJson!=null){
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			if((Double)map.get("stateID")==0 && (Double)map.get("businessState")==0){
				md.addObject("result",map);
			}
			md.addObject("userName",getHttpSession(request).getAttribute(userNameKey));
			md.addObject("userImg",getHttpSession(request).getAttribute(userImgKey));
			return md;
		}
		return md;
    }
	/***********优惠券****************************************************/
	/**
	 * 获取优惠券
	 */
	@RequestMapping("/getCouponList")
	public ModelAndView getCouponList(HttpServletRequest request){
		ModelAndView md = new ModelAndView("cardPackage");
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/HOS/GetCouponList",GsonUtil.toJson(promap),request,true);
		if(memberJson!=null && !memberJson.equals("gotoRegister")){
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			if((Double)map.get("stateID")==0 && (Double)map.get("businessState")==0){
				md.addObject("result",map.get("result"));
			}
			return md;
		}
		return md;
	}

    /***********联系人****************************************************/

	/**
	 * 获取常用入住人信息里列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/getMemCheckInList")
	public ModelAndView getMemCheckInList(HttpServletRequest request){
		ModelAndView md = new ModelAndView("memberCheckInList");
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/MEM/GetMemCheckInPeo",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			md=new ModelAndView("redirect:/home/gotoRegister");
			return md;
		}
		if(memberJson!=null){
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
			if((Double)map.get("stateID")==0 && (Double)map.get("businessState")==0){
				Object tmp = map.get("dataList");

				if(!"".equals(tmp)){
					list = (List<Map<String,Object>>)map.get("dataList");
					for(int i =0;i<list.size();i++){
						double idstr = (Double)list.get(i).get("ID");
						Integer id = (int)idstr;
						list.get(i).put("ID",id);
					}
				}
			}

			md.addObject("dataList",list);
		}
		return md;
	}

	/**
	 * 获取默认常用入住人信息里列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/getMemDefaultCheckInPeo")
	public ModelAndView getMemDefaultCheckInPeo(HttpServletRequest request){
		ModelAndView md = new ModelAndView("memberCheckInList");
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/MEM/GetMemDefaultCheckInPeo",GsonUtil.toJson(promap),request,true);
		if(memberJson!=null){
			List list = new ArrayList();
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			if((Double)map.get("stateID")==0 && (Double)map.get("businessState")==0){
				list =(ArrayList) map.get("dataList");
			}
			md.addObject("dataList",list);
		}
		return md;
	}

	/**
	 * 跳转添加入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoAddCheckInPeo")
	public ModelAndView gotoAddCheckInPeo(String memKey,HttpServletRequest request){
        ModelAndView md = new ModelAndView("addCheckIn");
        md.addObject("memKey",memKey);
        return md;
	}
	
	/**
	 * 订单页面跳转添加入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoAddCheckInPeoByOrder")
	public ModelAndView gotoAddCheckInPeoByOrder(String memKey,HttpServletRequest request,String checkedMsg,String type){
		ModelAndView md = new ModelAndView("addCheckInByOrder");
		md.addObject("memKey",memKey);
		md.addObject("checkedMsg",checkedMsg);
		md.addObject("checkedMsg",type);
		return md;
	}

	/**
	 * 添加入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/addCheckInSubmit")
	@ResponseBody
	public JSONObject addCheckInSubmit(HttpServletRequest request,String contactName,String contactPhone,Boolean defaultSign,String memKey){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ContactName",contactName);
		promap.put("ContactPhone",contactPhone);
		promap.put("DefaultSign",defaultSign);
		String memberJson=getHttpJson("Logistics/MEM/AddCheckInPeo",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			//ajax注册码返回4
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
            resultJson.put("memKey",memKey);
		}
		return resultJson;
	}

	/**
	 * 跳转修改入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoModifyMemberCheckInfo")
	public ModelAndView gotoModifyMemberCheckInfo(HttpServletRequest request,String id,String contactName,String contactPhone,Boolean defaultSign){
		ModelAndView md = new ModelAndView("modifyCheckIn");
		md.addObject("id",Integer.parseInt(id));
		md.addObject("contectName",contactName);
		md.addObject("contactPhone",contactPhone);
		md.addObject("defaultSign",defaultSign);
		return md;
	}

	/**
	 * 修改入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/modifyMemberCheckInfo")
	@ResponseBody
	public JSONObject modifyMemberCheckInfo(HttpServletRequest request,Integer id,String contactName,String contactPhone,Boolean defaultSign){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ID",id);
		promap.put("ContactName",contactName);
		promap.put("ContactPhone",contactPhone);
		promap.put("DefaultSign",defaultSign);
		String memberJson=getHttpJson("Logistics/MEM/EditCheckInPeo",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}

	/**
	 * 删除入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/delCheckInPeo")
	@ResponseBody
	public JSONObject delCheckInPeo(HttpServletRequest request,String id){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ID",id);
		String memberJson=getHttpJson("Logistics/MEM/DelCheckInPeo",GsonUtil.toJson(promap),request,true);
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}

	/**
	 * 设置默认入住人信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/setMemDefaultCheckInPeo")
	@ResponseBody
	public JSONObject setMemDefaultCheckInPeo(HttpServletRequest request,String id){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ID",id);
		String memberJson=getHttpJson("Logistics/MEM/SetMemDefaultCheckInPeo",GsonUtil.toJson(promap),request,true);
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}



	/***********常用地址****************************************************/
	/**
	 * 获取地址列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/getMemAddressList")
	public ModelAndView getMemAddressList(HttpServletRequest request){
		ModelAndView md = new ModelAndView("memberAddressList");
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/MEM/GetMemAddress",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			md=new ModelAndView("redirect:/home/gotoRegister");
			return md;
		}

		if(memberJson!=null){
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			Object tmp = map.get("dataList");
			List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
			if(!"".equals(tmp)){
				list = (List<Map<String,Object>>)map.get("dataList");
				for(int i =0;i<list.size();i++){
					double idstr = (Double)list.get(i).get("ID");
					Integer id = (int)idstr;
					list.get(i).put("ID",id);
				}
				md.addObject("dataList",list);
			}

		}
		return md;
	}

	/**
	 * 获取用户默认地址
	 * @param request
	 * @return
	 */
	@RequestMapping("/getMemDefaultAddress")
	@ResponseBody
	public JSONObject getMemDefaultAddress(HttpServletRequest request){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/MEM/GetMemDefaultAddress",GsonUtil.toJson(promap),request,true);
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}

	/**
	 * 跳转添加地址
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoAddMemAddress")
	public ModelAndView gotoAddMemAddress(HttpServletRequest request){
		ModelAndView md = new ModelAndView("addAddress");
		return md;
	}


	/**
	 * 添加地址
	 * @param request
	 * @return
	 */
	@RequestMapping("/addMemAddressSubmit")
	@ResponseBody
	public JSONObject addMemAddressSubmit(HttpServletRequest request,String contactName,Long contactPhone,String addressDetail,String provinceCode,String cityCode,String districtCode,String defaultSign){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ProvinceCode",provinceCode);
		promap.put("CityCode",cityCode);
		promap.put("DistrictCode",districtCode);
		promap.put("ContactName",contactName);
		promap.put("ContactPhone",contactPhone);
		promap.put("AddressDetail",addressDetail);
		promap.put("DefaultSign",defaultSign);

		String memberJson=getHttpJson("Logistics/MEM/AddMemAddress",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}

	/**
	 * 跳转修改地址
	 * @param request
	 * @return
	 *String contactName,Integer contactPhone,String addressDetail,Boolean defaultSign
	 */
	@RequestMapping("/gotoEditMemAddress")
	public ModelAndView gotoEditMemAddress(HttpServletRequest request,String id,String contactName,
										   String contactPhone,String addressDetail,
										   String provinceCode,String cityCode,String districtCode,
										   Boolean defaultSign,String addressName){
		ModelAndView md = new ModelAndView("modifyAddress");
		md.addObject("id",id);
		md.addObject("contactName",contactName);
		md.addObject("contactPhone",contactPhone);
		md.addObject("addressDetail",addressDetail);
		md.addObject("provinceCode",provinceCode);
		md.addObject("cityCode",cityCode);
		md.addObject("districtCode",districtCode);
		md.addObject("addressCode",provinceCode+" "+cityCode+" "+districtCode);
		md.addObject("defaultSign",defaultSign);
		md.addObject("defaultSign",defaultSign);
		md.addObject("addressName",addressName);
		return md;
	}

	/**
	 * 修改地址
	 * @param request
	 * @return
	 */
	@RequestMapping("/editMemAddress")
	@ResponseBody
	public JSONObject editMemAddress(HttpServletRequest request,String id,String contactName,
									 Integer contactPhone,String addressDetail,
									 String provinceCode,String cityCode,String districtCode,
									 Boolean defaultSign){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ProvinceCode",provinceCode);
		promap.put("CityCode",cityCode);
		promap.put("DistrictCode",districtCode);
		promap.put("id",id);
		promap.put("ContactName",contactName);
		promap.put("ContactPhone",contactPhone);
		promap.put("AddressDetail",addressDetail);
		promap.put("DefaultSign",defaultSign);
		String memberJson=getHttpJson("Logistics/MEM/EditMemAddress",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson =JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}


	/**
	 * 删除地址
	 * @param request
	 * id
	 * @return
	 */
	@RequestMapping("/delMemAddress")
	@ResponseBody
	public JSONObject delMemAddress(HttpServletRequest request, String id){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ID",id);
		String memberJson=getHttpJson("Logistics/MEM/DelMemAddress",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}

	/**
	 * 设置默认地址
	 * @param request
	 * id
	 * @return
	 */
	@RequestMapping("/setMemDefaultAddress")
	@ResponseBody
	public JSONObject setMemDefaultAddress(HttpServletRequest request,String id){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("ID",id);
		String memberJson=getHttpJson("Logistics/MEM/SetMemDefaultAddress",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}



	/***********发票****************************************************/
	/**
	 * 获取发票列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/getMemInvoiceList")
	public ModelAndView getMemInvoiceList(HttpServletRequest request){
		ModelAndView md = new ModelAndView("memberInvoiceList");
		Map<String,Object> promap = new HashMap<String,Object>();
		String memberJson=getHttpJson("Logistics/MEM/GetMemInvoiceList",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			md=new ModelAndView("redirect:/home/gotoRegister");
			return md;
		}

		if(memberJson!=null){
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			Object tmp = map.get("dataList");
			List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
			if(!"".equals(tmp)){
				list = (List<Map<String,Object>>)tmp;
				if(list.size()>0){
					for(int i =0;i<list.size();i++){
						double takeTypeStr = (Double)list.get(i).get("TakeType");
						double invoiceTypeStr = (Double)list.get(i).get("InvoiceType");
						Integer TakeType = (int)takeTypeStr;
						Integer InvoiceType = (int)invoiceTypeStr;
						list.get(i).put("TakeType",TakeType);
						list.get(i).put("InvoiceType",InvoiceType);
					}
				}
				md.addObject("dataList",list);
			}
		}
		return md;
	}


	/**
	 * 跳转添加普通发票
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoAddOrdinaryInvoice")
	public ModelAndView gotoAddOrdinaryInvoice(HttpServletRequest request,Integer type,Boolean needInvoice){
		ModelAndView md = new ModelAndView("addOrdinaryInvoice");
		if(type==null){
			type=1;
		}
		if(type==2){
			md.addObject("needInvoice",needInvoice);
		}
		md.addObject("type",type);
		return md;
	}

	/**
	 * 跳转添加增值税发票
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoAddValueInvoice")
	public ModelAndView gotoAddValueInvoice(HttpServletRequest request,Integer type,Boolean needInvoice){
		ModelAndView md = new ModelAndView("addValueInvoice");
		if(type==null){
			type=1;
		}
		if(type==2){
			md.addObject("needInvoice",needInvoice);
		}
		md.addObject("type",type);
		return md;
	}

	/**
	 * 添加发票
	 * @param request
	 * @return
	 */
	@RequestMapping("/addMemInvoiceSubmit")
	@ResponseBody
	public JSONObject addMemInvoiceSubmit(HttpServletRequest request, String invoiceType,String title,
										  String creditCode,String registerAddress,String companyPhone,String openingBank,
										  String openingAccount,String takeType,Boolean defaultSign,Boolean needInvoice){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("InvoiceType",invoiceType);
		promap.put("Title",title);
		promap.put("CreditCode",creditCode);
		promap.put("RegisterAddress",registerAddress);
		promap.put("CompanyPhone",companyPhone);
		promap.put("OpeningBank",openingBank);
		promap.put("OpeningAccount",openingAccount);
		promap.put("TakeType",takeType);
		promap.put("DefaultSign",defaultSign);
		String memberJson=getHttpJson("Logistics/MEM/AddInvoice",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson =JSONObject.fromObject(memberJson);
		}
        resultJson.put("needInvoice",needInvoice);
		return resultJson;
	}
	/**
	 * 跳转修改普通发票
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoEditOrdinaryInvoice")
	public ModelAndView gotoEditOrdinaryInvoice(HttpServletRequest request,String code,String invoiceType,String title,
										   String creditCode,String takeType,Boolean defaultSign,Integer type){
		if(type==null){
			type=1;
		}
		ModelAndView md = new ModelAndView("modifyOrdinaryInvoice");
		md.addObject("code",code);
		md.addObject("invoiceType",invoiceType);
		md.addObject("title",title);
		md.addObject("creditCode",creditCode);
		md.addObject("takeType",Double.valueOf(takeType));
		md.addObject("defaultSign",defaultSign);
		md.addObject("type",type);
		return md;
	}

	/**
	 * 跳转修改增值发票
	 * @param request
	 * @return
	 */
	@RequestMapping("/gotoEditValueInvoice")
	public ModelAndView gotoEditValueInvoice(HttpServletRequest request,String code,String invoiceType,String title,
										   String creditCode,String registerAddress,String companyPhone,String openingBank,
										   String openingAccount,String takeType,Boolean defaultSign,Integer type){
		ModelAndView md = new ModelAndView("modifyValueInvoice");
		md.addObject("code",code);
		md.addObject("invoiceType",invoiceType);
		md.addObject("title",title);
		md.addObject("creditCode",creditCode);
		md.addObject("takeType",Double.valueOf(takeType));
		md.addObject("defaultSign",defaultSign);

		md.addObject("registerAddress",registerAddress);
		md.addObject("companyPhone",companyPhone);
		md.addObject("openingBank",openingBank);
		md.addObject("openingAccount",openingAccount);
		md.addObject("type",type);
		return md;
	}

	/**
	 * 修改发票
	 * @param request
	 * @return
	 */
	@RequestMapping("/editMemInvoice")
	@ResponseBody
	public JSONObject editMemInvoice(HttpServletRequest request,String code,String invoiceType,String title,
									 String creditCode,String registerAddress,String companyPhone,String openingBank,
									 String openingAccount,String takeType,Boolean defaultSign){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("Code",code);
		promap.put("InvoiceType",invoiceType);
		promap.put("Title",title);
		promap.put("CreditCode",creditCode);
		promap.put("RegisterAddress",registerAddress);
		promap.put("CompanyPhone",companyPhone);
		promap.put("OpeningBank",openingBank);
		promap.put("OpeningAccount",openingAccount);
		promap.put("TakeType",takeType);
		promap.put("DefaultSign",defaultSign);
		String memberJson=getHttpJson("Logistics/MEM/EditInvoice",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson =JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}


	/**
	 * 删除发票
	 * @param request
	 * id
	 * @return
	 */
	@RequestMapping("/delMemInvoice")
	@ResponseBody
	public JSONObject delMemInvoice(HttpServletRequest request, String code){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("Code",code);
		String memberJson=getHttpJson("Logistics/MEM/DelInvoice",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}

	/**
	 * 设置默认发票
	 * @param request
	 * id
	 * @return
	 */
	@RequestMapping("/setMemDefaultInvoice")
	@ResponseBody
	public JSONObject setMemDefaultInvoice(HttpServletRequest request,String code){
		JSONObject resultJson = new JSONObject();
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("Code",code);
		String memberJson=getHttpJson("Logistics/MEM/SetMemDefaultInvoice",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			resultJson.put("stateID",4);
		}
		if(memberJson!=null){
			resultJson = JSONObject.fromObject(memberJson);
		}
		return resultJson;
	}


    /**
     * 获取会员二维码信息
     * @param request
     * @return
     */
    @RequestMapping("/getMemQRCode")
    public ModelAndView getMemQRCode(HttpServletRequest request){
        ModelAndView md = new ModelAndView("memberCode");
        Map<String,Object> promap = new HashMap<String,Object>();
        promap.put("RequestUrl",GetConfig.getString("base_url")+"member/getMemQRCode");
        String memberJson=getHttpJson("Logistics/MEM/GetMemQRCode",GsonUtil.toJson(promap),request,true);
        if("gotoRegister".equals(memberJson)){
        	md=new ModelAndView("redirect:/home/gotoRegister");
			md.addObject("namespase","member");
			md.addObject("url","memberCenter");
        }
        else if(memberJson!=null){
            Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
            md.addObject("useCode",map.get("Ticket"));
			md.addObject("userName",getHttpSession(request).getAttribute(userNameKey));
			md.addObject("userImg",getHttpSession(request).getAttribute(userImgKey));
			md.addObject("codeMap",map);
        }
//    	String ticket=(String) getHttpSession(request).getAttribute(tokenKey);
//    	if(ticket==null){
//    		ticket=WebChatUtil.getJsTicket();
//    		getHttpSession(request).setAttribute(tokenKey,ticket);
//    	}
    	Map<String, String> map = WebChatUtil.getJsapi(GetConfig.getString("base_url")+"member/getMemQRCode");
    	md.addObject("link",GetConfig.getString("base_url")+"member/shareHtml?memKey="+getMemKey(request)+"#NO#NO#");
    	md.addObject("wxMap",map);
        return md;
    }
    
    /**
     * 获取会员二维码信息
     * @param request
     * @return
     */
    @RequestMapping("/shareHtml")
    public ModelAndView shareHtml(HttpServletRequest request){
        ModelAndView md = new ModelAndView("shareHtml");
        Map<String,Object> promap = new HashMap<String,Object>();
        String memberJson=getHttpJson("Logistics/MEM/GetMemQRCode",GsonUtil.toJson(promap),request,true);
        if(memberJson!=null){
            Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
            md.addObject("useCode",map.get("Ticket"));
			md.addObject("codeMap",map);
        }
        return md;
    }


    /**
     * 找回密码
     * @param request
     * id
     * @return
     */
    @RequestMapping("/getMemPassword")
    @ResponseBody
    public JSONObject getMemPassword(HttpServletRequest request,String phone,String captcha ){
        JSONObject resultJson = new JSONObject();
        if(phone==null||captcha==null){
            resultJson.put("stateID",3);
        }
        Map<String,Object> promap = new HashMap<String,Object>();
        promap.put("Phone",phone);
        promap.put("Captcha",captcha);
        String memberJson=getHttpJson("Logistics/MEM/GetMemPassword",GsonUtil.toJson(promap),request,true);
        if("gotoRegister".equals(memberJson)){
            resultJson.put("stateID",4);
        }
        if(memberJson!=null){
            resultJson = JSONObject.fromObject(memberJson);
        }
        return resultJson;
    }


    /**
     * 跳转修改密码
     * @param request
     * @return
     */
    @RequestMapping("/gotoChangeMemPassword")
    public ModelAndView gotoChangeMemPassword(HttpServletRequest request){
        ModelAndView md = new ModelAndView("changePassword");
        return md;
    }

    /**
     * 修改密码
     * @param request
     * id
     * @return
     */
    @RequestMapping("/changeMemPassword")
    @ResponseBody
    public JSONObject changeMemPassword(HttpServletRequest request,String oldPassword,String newPassword,String confirmNewPassword){
        JSONObject resultJson = new JSONObject();
        if(oldPassword==null||newPassword==null||confirmNewPassword==null||(!confirmNewPassword.equals(newPassword))){
            resultJson.put("stateID",3);
        }
        Map<String,Object> promap = new HashMap<String,Object>();
        promap.put("OldPassword",oldPassword);
        promap.put("NewPassword",newPassword);
        promap.put("ConfirmNewPassword",confirmNewPassword);
        String memberJson=getHttpJson("Logistics/MEM/ChangeMemPassword",GsonUtil.toJson(promap),request,true);
        if("gotoRegister".equals(memberJson)){
            resultJson.put("stateID",4);
        }
        if(memberJson!=null){
            resultJson = JSONObject.fromObject(memberJson);
        }
        return resultJson;
    }


	/**
	 * 我的评价
	 */
	@RequestMapping("/evaluate")
	public ModelAndView evaluate(HttpServletRequest request,Integer pageIndex,Integer pageSize,String hotelKey,
										String startDate,String endDate,String city,String cityName,String lng,String lat,String type){
		ModelAndView md = new ModelAndView("myEvaluateList");
		if(pageIndex==null){
			pageIndex=1;
		}
		if(pageSize==null){
			pageSize=1000;
		}
		Map<String,Object> promap = new HashMap<String,Object>();
		promap.put("PageIndex",pageIndex);
		promap.put("PageSize",pageSize);
		String memberJson=getHttpJson("Logistics/SAL/QueryMemEvaluate",GsonUtil.toJson(promap),request,true);
		if("gotoRegister".equals(memberJson)){
			md=new ModelAndView("redirect:/home/gotoRegister");
			return md;
		}
		if(memberJson!=null) {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			Map<String,Object> map = GsonUtil.fromJson(memberJson,new TypeToken<Map<String, Object>>(){}.getType());
			if((Double)map.get("stateID")==0 && (Double)map.get("businessState")==0){
				Object tmp = map.get("dataList");

				if (!"".equals(tmp)) {
					list = (List<Map<String, Object>>) tmp;
					if (list.size() > 0) {
						for (int i = 0; i < list.size(); i++) {
							double gradeStr = (Double) list.get(i).get("Grade");
							Integer Grade = (int) gradeStr;
							list.get(i).put("Grade", Grade);
							String createDataStr = list.get(i).get("CreateDate").toString();
							createDataStr = createDataStr.substring(0,createDataStr.indexOf(" "));
                            list.get(i).put("CreateDate", createDataStr);
                            double idStr = (Double) list.get(i).get("ID");
                            Integer id = (int) idStr;
                            list.get(i).put("ID", id);
						}
					}
				}
			}
			md.addObject("dataList", list);
			md.addObject("size", list.size());

		}
		md.addObject("hotelKey", hotelKey);
		md.addObject("startDate",startDate);
		md.addObject("endDate",endDate);
		md.addObject("hotelKey",hotelKey);
		md.addObject("cityName",cityName);
		md.addObject("city",city);
		md.addObject("lng",lng);
		md.addObject("lat",lat);
		md.addObject("type",type);
		return md;
	}



	/**
	 * 退出登录
	 * loginOut
	 * @param request
	 * @return
	 */
	@RequestMapping("/loginOut")
	public ModelAndView loginOut(HttpServletRequest request){
		ModelAndView md = new ModelAndView("index");
		baseLoginOut(request);
		md=new ModelAndView("redirect:/home/index");
		return md;
	}
}
